package cn.orangelite.ai.controller;

import cn.orangelite.ai.domain.AiGptRole;
import cn.orangelite.ai.service.IAiGptRoleService;
import cn.orangelite.common.core.utils.poi.ExcelUtil;
import cn.orangelite.common.core.web.controller.BaseController;
import cn.orangelite.common.core.web.domain.AjaxResult;
import cn.orangelite.common.core.web.page.TableDataInfo;
import cn.orangelite.common.log.annotation.Log;
import cn.orangelite.common.log.enums.BusinessType;
import cn.orangelite.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * gpt角色Controller
 *
 * @author dongfaqing
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/gpt/role")
public class AiGptRoleController extends BaseController
{
    @Autowired
    private IAiGptRoleService aiGptRoleService;

    /**
     * 查询gpt角色列表
     */
    @RequiresPermissions("ai:role:list")
    @GetMapping("/list")
    public TableDataInfo list(AiGptRole aiGptRole)
    {
        startPage();
        List<AiGptRole> list = aiGptRoleService.selectAiGptRoleList(aiGptRole);
        return getDataTable(list);
    }

    /**
     * 导出gpt角色列表
     */
    @RequiresPermissions("ai:role:export")
    @Log(title = "gpt角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiGptRole aiGptRole)
    {
        List<AiGptRole> list = aiGptRoleService.selectAiGptRoleList(aiGptRole);
        ExcelUtil<AiGptRole> util = new ExcelUtil<AiGptRole>(AiGptRole.class);
        util.exportExcel(response, list, "gpt角色数据");
    }

    /**
     * 获取gpt角色详细信息
     */
    @RequiresPermissions("ai:role:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiGptRoleService.selectAiGptRoleById(id));
    }

    /**
     * 新增gpt角色
     */
    @RequiresPermissions("ai:role:add")
    @Log(title = "gpt角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiGptRole aiGptRole)
    {
        return toAjax(aiGptRoleService.insertAiGptRole(aiGptRole));
    }

    /**
     * 修改gpt角色
     */
    @RequiresPermissions("ai:role:edit")
    @Log(title = "gpt角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiGptRole aiGptRole)
    {
        return toAjax(aiGptRoleService.updateAiGptRole(aiGptRole));
    }

    /**
     * 删除gpt角色
     */
    @RequiresPermissions("ai:role:remove")
    @Log(title = "gpt角色", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiGptRoleService.deleteAiGptRoleByIds(ids));
    }
}
